'use strict';

const Controller = require('egg').Controller;

class TravlController extends Controller {
  // 详情页的两个推荐
  async index() {
    let sqlcity=`SELECT *  FROM travelguide WHERE secondcity='南京' OR  secondcity='厦门'`;
    let ressql=await this.app.mysql.query(sqlcity);
    // console.log(ressql,111);
    let finarr=ressql.map((el)=>{
      return JSON.parse(el.siteimg);
    });
    for(let j=0;j<ressql.length;j++){
        ressql[j].siteimg=finarr[j];
    }
    // console.log(finarr,222)
    this.ctx.body = {ressql};
  }
  // 点击之后主页面需要的信息
  async travlcity(){
    let firstcity=this.ctx.request.query.firstcity;
    // console.log(this.ctx.request.query,this.ctx.request.query.firstcity)
    let sqlselect=`SELECT *  FROM travelguide WHERE firstcity='${firstcity}'`;
    let cityselect=await this.app.mysql.query(sqlselect);
    let cityarr=cityselect.map((el)=>{
      return JSON.parse(el.siteimg);
    });
    // console.log(cityarr,Object.prototype.toString.call(cityarr),7777)
    for(let i=0;i<cityselect.length;i++){
      cityselect[i].siteimg=cityarr[i];
    }
    // console.log(cityselect,6666)
    this.ctx.body={cityselect};
  }
}

module.exports = TravlController;
